<template>
    <view class="page-invitation-list">
		<u-sticky>
			<!-- 只能有一个根元素 -->
			<view class="search-sticky">
				<u-row gutter="0">
					<u-col span="4" v-for="(item,index) in tab.list" :key="index">
						<view class="text-center">
                            <view class="inline-block" :class="tab.current == index ? 'current' : ''" @click="changeTab(index)">
                                <text class="name">{{ item.name }}</text>
                            </view>
                        </view> 
					</u-col>
				</u-row>
			</view>
		</u-sticky>
		<view class="p-4" v-if="tab.list[tab.current].records.length == 0">
            <u-empty text="暂无内容" mode="list"></u-empty>
        </view> 
		<view class="list">
			<u-gap height="30"></u-gap>
			<view class="fly-panel" v-for="(item,index) in tab.list[tab.current].records" :key="index">
				<view class="hd"><view class="title">{{ proxy.$util.setName(item.type, optionData.billType) }}</view></view>
				<view class="bd">
					<view>
						<fly-info label="订单号" :value="item.billId"></fly-info>
						<!-- <fly-info label="活动名称" v-if="item.type == 'activities'" :value="proxy.$util.setName(item.relationshipId, optionData.cardList)"></fly-info> -->
						<!-- <fly-info label="卡类型" v-else :value="proxy.$util.setName(item.relationshipId, optionData.cardList)"></fly-info> -->
						<fly-info :label="item.type == 'activities' ? '活动名称' : '卡类型'" :value="item.relationshipName"></fly-info>
						<fly-info label="金额" :value="item.amount + '元'"></fly-info>
						<fly-info label="状态" :value="proxy.$util.setName(item.status, optionData.billStatus)"></fly-info>
						<fly-info label="支付时间" :value="item.payTime"></fly-info>
					</view>					
				</view>
				<view class="ft" v-if="item.status == '1'">
					<u-button class="btn-red" size="mini" @click="handleRefund(item)">退款</u-button>
				</view>
			</view>
		</view>
    </view>
</template>
<script setup lang="ts">
import dayjs from 'dayjs';
import FlyInfo from '@/components/FlyInfo';
import {onShow, onPullDownRefresh, onReachBottom, onShareAppMessage } from '@dcloudio/uni-app';
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
import { useAppStore } from '@/stores/app'
import { useOptionData } from '@/stores/optionData';
let appStore = useAppStore();
const optionDataStore = useOptionData();
let tab = reactive({
	current: 0,
	list:[
		{id:1, name: '已支付', records: [], current: 1, size: 10, total:0},
		{id:2, name: '已退款', records: [], current: 1, size: 10, total:0},
	],
	invitationId: null,
});
let optionData = reactive({});
const getInitData = async () => {
    optionData.durationType = await optionDataStore.getDictList('duration_type');
    optionData.billStatus = await optionDataStore.getDictList('bill_status');
    optionData.billType = await optionDataStore.getDictList('bill_type');
	let cardList = await proxy.$http('get', '/admin/membershipCards/page', {current:1, size:30});
	optionData.cardList = cardList.records.map(item => {
		item.id = item.cardId;
		item.name = item.cardName;
		return item;
	});
};
const handleRefund = (item) => {
	uni.showModal({
		title: '确定要退款吗？',
		editable: true,
		placeholderText: '请输入备注',
		success: res => {
			if(res.confirm){
				let params = {
					billId: item.billId,
					type: item.type,
					remark: res.content
				}
				proxy.$http('post', '/admin/refundApply', params, (data,msg) => {
					uni.showToast({title: '提交成功', icon: 'none'});
					getList('refresh');
				})
			}
		}
	})
};
const changeTab = (i) => {
	tab.current = i;
    if(tab.list[tab.current].records.length == 0){
        getList('refresh');
    }
}
const getList = (type) => {
    let obj = tab.list[tab.current];
      if(type == 'refresh'){  
        obj.current = 1;
        obj.records = [];
      }else{
        if(obj.total > obj.records.length){
          obj.current ++;        
        }else{
          uni.showToast({title:'没有更多了',icon: 'none'});
          return;
        }
      };
      let params = {
        current: obj.current,
        size: obj.size,
        status: obj.id,
        // status: 0,
      };
      proxy.$http('get', '/admin/bill/xcxPage', proxy.$util.getParam(params) ,(data,msg) => {
        obj.records = obj.records.concat(data.records);
        obj.total = data.total;
      },msg => {

      })
};
onPullDownRefresh(() => {
	getList('refresh');
	setTimeout( () => {
		uni.stopPullDownRefresh();
	}, 1000);
});
onReachBottom(() =>{
	getList();
});
onShow(() => {
	getInitData();
	getList('refresh');
})
</script>